from tkinter import *

root = Tk()
root.title("Cul By 刘明洋")

def show0():
    label['text'] = label['text'] + '0'

def show1():
    label['text'] = label['text'] + '1'

def show2():
    label['text'] = label['text'] + '2'

def show3():
    label['text'] = label['text'] + '3'

def show4():
    label['text'] = label['text'] + '4'

def show5():
    label['text'] = label['text'] + '5'

def show6():
    label['text'] = label['text'] + '6'

def show7():
    label['text'] = label['text'] + '7'

def show8():
    label['text'] = label['text'] + '8'

def show9():
    label['text'] = label['text'] + '9'

# ←
def showback():
    label['text'] = label['text'][:-1]

def showDiv():
    if label['text'] and label['text'][-1] in ['+','-','*','÷']:
        label['text'] = label['text'][:-1] + '÷'
    else:
        label['text'] = label['text'] + '÷'

def showMul():
    if label['text'] and label['text'][-1] in ['+','-','*','÷']:
        label['text'] = label['text'][:-1] + '*'
    else:
        label['text'] = label['text'] + '*'
def showDot():
    label['text'] = label['text'] + '.'

def showDY():
    label['text'] = label['text'] + '='

def showadd():
    if label['text'] and label['text'][-1] in ['+','-','*','÷']:
        label['text'] = label['text'][:-1] + '+'
    else:
        label['text'] = label['text'] + '+'
def showSub():
    if label['text'] and label['text'][-1] in ['+','-','*','÷']:
        label['text'] = label['text'][:-1] + '-'
    else:
        label['text'] = label['text'] + '-'
def showCle():
    label['text'] =''
def showDY():
    result = eval(label['text'])
    label['text'] = str(result)

# 显示屏
label = Label(root, bg="papayawhip", text='', height=4, fg='black',font='simplex 16')
label.grid(row=0,column=0,sticky='NSEW',columnspan=5)

# 第1行 ←/sinx/cos/ 4/5 /C
btnArr = Button(root,text="←",bg='pink',fg='white',relief="groove",width=5,height=2,command=showback)
btnArr.grid(row=1,column=0,sticky='NSEW')
btnSin = Button(root,text="sinx",bg='pink',fg='white',relief="groove",width=5,height=2)
btnSin.grid(row=1,column=1,sticky='NSEW')
btnCos = Button(root,text="cosx",bg='pink',fg='white',relief="groove",width=5,height=2)
btnCos.grid(row=1,column=2,sticky='NSEW')
btnFf = Button(root,text="≈",bg='pink',fg='white',relief="groove",width=5,height=2)
btnFf.grid(row=1,column=3,sticky='NSEW')
btnCle = Button(root,text="C",bg='pink',fg='white',relief="groove",width=5,height=2, command=showCle)
btnCle.grid(row=1,column=4,sticky='NSEW')

# 第2行 7/8/9/÷/x²
btn7 = Button(root,text="7",bg='palevioletred',fg='white',relief="groove",width=5,height=2,command=show7)
btn7.grid(row=2,column=0,sticky='NSEW')
btn8 = Button(root,text="8",bg='palevioletred',fg='white',relief="groove",width=5,height=2,command=show8)
btn8.grid(row=2,column=1,sticky='NSEW')
btn9 = Button(root,text="9",bg='palevioletred',fg='white',relief="groove",width=5,height=2,command=show9)
btn9.grid(row=2,column=2,sticky='NSEW')
btnDiv= Button(root,text="÷",bg='palevioletred',fg='white',relief="groove",width=5,height=2,command=showDiv)
btnDiv.grid(row=2,column=3,sticky='NSEW')
btnSqu= Button(root,text="x²",bg='pink',fg='white',relief="groove",width=5,height=2)
btnSqu.grid(row=2,column=4,sticky='NSEW')

# 第3行 4/5/6/*/|x|
btn4 = Button(root,text="4",bg='palevioletred',fg='white',relief="groove",width=5,height=2,command=show4)
btn4.grid(row=3,column=0,sticky='NSEW')
btn5 = Button(root,text="5",bg='palevioletred',fg='white',relief="groove",width=5,height=2,command=show5)
btn5.grid(row=3,column=1,sticky='NSEW')
btn6 = Button(root,text="6",bg='palevioletred',fg='white',relief="groove",width=5,height=2,command=show6)
btn6.grid(row=3,column=2,sticky='NSEW')
btnaMul= Button(root,text="*",bg='palevioletred',fg='white',relief="groove",width=5,height=2, command=showMul)
btnaMul.grid(row=3,column=3,sticky='NSEW')
btnaAbs= Button(root,text="|x|",bg='pink',fg='white',relief="groove",width=5,height=2)
btnaAbs.grid(row=3,column=4,sticky='NSEW')

# 第4行 1/2/3/-
btn1 = Button(root,text="1",bg='palevioletred',fg='white',relief="groove",width=5,height=2,command=show1)
btn1.grid(row=4,column=0,sticky='NSEW')
btn2 = Button(root,text="2",bg='palevioletred',fg='white',relief="groove",width=5,height=2,command=show2)
btn2.grid(row=4,column=1,sticky='NSEW')
btn3 = Button(root,text="3",bg='palevioletred',fg='white',relief="groove",width=5,height=2,command=show3)
btn3.grid(row=4,column=2,sticky='NSEW')
btnSub= Button(root,text="-",bg='palevioletred',fg='white',relief="groove",width=5,height=2, command=showSub)
btnSub.grid(row=4,column=3,sticky='NSEW')

# 第5行 0/./+/=
btn0 = Button(root,text="0",bg='palevioletred',fg='white',relief="groove",width=5,height=2,command=show0)
btn0.grid(row=5,column=0,columnspan=2,sticky='NSEW')
btnDot = Button(root,text=".",bg='palevioletred',fg='white',relief="groove",width=5,height=2, command=showDot)
btnDot.grid(row=5,column=2,sticky='NSEW')
btnadd= Button(root,text="+",bg='palevioletred',fg='white',relief="groove",width=5,height=2, command=showadd)
btnadd.grid(row=5,column=3,sticky='NSEW')
btnaDY= Button(root,text="=",bg='pink',fg='white',relief="groove",width=5,height=2, command=showDY)
btnaDY.grid(row=4,column=4,rowspan=2,sticky='NSEW')





root.mainloop()